home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1366 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: news.mindlink.net!news
  2. From: genew@mindlink.bc.ca (Gene Wirchenko)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: char* to char array[] ?
  5. Date: Sat, 13 Jan 1996 05:51:32 GMT
  6. Organization: MIND LINK! - British Columbia, Canada
  7. Message-ID: <4d7hb4$gak@fountain.mindlink.net>
  8. References: <4d4n9s$9uv@ixnews2.ix.netcom.com> <1996Jan13.013852.19365@hns.com>
  9. NNTP-Posting-Host: line078.nwm.mindlink.net
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Ralph Sweitzer <t_rsweitzer> wrote:
  13.  
  14. >Try something like this it should work.
  15.  
  16. >/* prototype */
  17. >char *called_finction(void);
  18.  
  19. >void calling_function(void)
  20. >{
  21. >  char *ptr;
  22. >  ptr = called_function();
  23. >}
  24.  
  25. >char *called_function(void)
  26. >{
  27. >  char buf[] = {"hello world"};
  28. >  return((char *)buf);
  29. >}
  30. >-- 
  31. >Ralph Sweitzer
  32.  
  33.      No, it won't work.  The storage for buf[] in called_function()
  34. will be released when that function terminates.  This will make the
  35. returned pointer invalid.
  36.  
  37.      Have a look at the FAQ.
  38.  
  39. Sincerely,
  40.  
  41. Gene Wirchenko
  42.  
  43. C Pronunciation Guide:
  44.      y=x++;     "wye equals ex plus plus semicolon"
  45.      x=x++;     "ex equals ex doublecross semicolon"
  46.  
  47.